﻿Imports LecturerAppointmentSystem.callback
Imports System.Net
Imports System.IO

Public Class Login2
    Inherits System.Web.UI.Page

    Dim facebookId As Integer

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Me.ClientScript.GetPostBackEventReference(Me, "arg")
        If IsPostBack Then
            Dim eventTarget As String = Me.Request("__EVENTTARGET")
            Dim eventArgument As String = Me.Request("__EVENTARGUMENT")

            If eventTarget <> String.Empty AndAlso eventTarget = "callPostBack" Then
                If eventArgument <> String.Empty Then
                    txtJSValue.Text = eventArgument
                    facebookId = eventArgument
                End If
            End If
        Else
            btnJSValue.Attributes.Add("onClick", "getAccessToken();")
        End If
    End Sub

    <System.Web.Services.WebMethod()> _
    Public Shared Function GetFacebookUserJSON(ByVal userid As String, ByVal access_token As String) As String
        Dim url As String = String.Format("https://graph.facebook.com/{0}?access_token={1}&fields=email,name,first_name,last_name,link", userid, access_token)

        Dim wc As New WebClient()
        Dim data As Stream = wc.OpenRead(url)
        Dim reader As New StreamReader(data)
        Dim s As String = reader.ReadToEnd()
        data.Close()
        reader.Close()

        Return s
    End Function

    'Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
    '    Response.Write(Hidden1.Value)
    'End Sub
End Class